package com.wing.qualification.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.contract.model.entity.ContractCategory;
import com.wing.contract.model.response.ContractCategoryVO;
import com.wing.qualification.dao.QualificationTypeDao;
import com.wing.qualification.model.entity.QualificationType;
import com.wing.qualification.model.request.QualificationTypeForm;
import com.wing.qualification.model.response.QualificationTypeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 资质类型-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class QualificationTypeServiceImpl extends ServiceImpl<QualificationTypeDao, QualificationType> implements QualificationTypeService {

    @Override
    public int add(QualificationTypeForm qualificationTypeForm) {

        //校验

        QualificationType qualificationType =new QualificationType();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(QualificationType.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(qualificationTypeForm, qualificationType, copyOptions);

        return baseMapper.insert(qualificationType);
    }

    @Override
    public List<QualificationTypeVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<QualificationTypeVO> pageList4app(Page page, Map<String, Object> params) {
        List<QualificationTypeVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public QualificationTypeVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public int enable(Long id) {
        QualificationTypeVO qualificationTypeVO =baseMapper.get4appById(id);
        if (qualificationTypeVO!=null){
            QualificationType qualificationType = new QualificationType();
            qualificationType.setId(id);
            qualificationType.setIsDeleted(true);
            int updateCount=baseMapper.updateById(qualificationType);
            return updateCount;
        }
        return 0;
    }

    @Override
    public int disable(Long id) {
        QualificationTypeVO qualificationTypeVO=baseMapper.get4appById(id);
        if (qualificationTypeVO!=null){
            QualificationType qualificationType = new QualificationType();
            qualificationType.setId(id);
            qualificationType.setIsDeleted(false);
            int updateCount=baseMapper.updateById(qualificationType);
            return updateCount;
        }

        return 0;
    }
}
